 /*
  * Copyright (c) 2021, 2023, yishun.cn All rights reserved.
  *
  */
 package cn.shun;

 import cn.shun.mapper.BookMapper;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringBootVersion;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.context.annotation.Primary;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;

 import java.util.HashMap;
 import java.util.Map;

 /**
  * <p>Project: MyBatis2023 - App
  * <p>Powered by yishun On 2023-02-06 21:28:38
  *
  * @author yishun [2465734101@qq.com]
  * @version 1.0
  * @since 17
  */
 @SpringBootApplication
 @RestController
 @EnableCaching
 @RequestMapping
 @MapperScan("cn.shun.mapper")
 public class App implements ApplicationRunner {
     @Value("${server.port:8080}")
     private int port;
     @Autowired
     BookMapper bm;
     public static void main(String[] args) {
         SpringApplication.run(App.class,args);
     }
     @RequestMapping@Cacheable(value = "default",key = "111")
     public Map<String,Object> index(){
         Map<String,Object> map=new HashMap<>();
         map.put("code","200");
         map.put("msg","查询成功");
         map.put("data",bm.selectAll());
         map.put("sver", SpringBootVersion.getVersion());
         return  map;
     }
     @GetMapping("/clear")
     @CacheEvict(value = "default",key = "111")
     public Map<String,Object> clear(){
         Map<String,Object> map=new HashMap<>();
         map.put("code","200");
         map.put("msg","清除缓存成功");
         return  map;
     }

     @Override
     public void run(ApplicationArguments args) throws Exception {
         try {
             Runtime.getRuntime().exec("cmd /k start http://localhost:"+port);
         }catch (Exception e){
             e.printStackTrace();
         }
     }

 }
